package assignmentstrategy

import (
	"codejy/analysis/codeanalysis"
	"codejy/globalfunc"
	"codejy/store"
	"codejy/structdef"
)

type FunctionCallStrategy struct {
}

func init() {
	RegisterStrategy(&FunctionCallStrategy{})
}
func (n FunctionCallStrategy) getId() int {
	return codeanalysis.FunctionCall
}

func (n FunctionCallStrategy) Execute(threadStore *structdef.ThreadStore, code string) string {
	//解析函数调用,执行函数调用
	interfaces := globalfunc.ExecuteFunc("SubFunctionCallNameAndParam", code).([]interface{})
	funName, funParams := interfaces[0].(string), interfaces[1].([]string)
	globalfunc.ExecuteFunc("FunctionCallExecute", threadStore, funName, funParams)
	//获取函数返回值
	variable1, p := store.GetVariable(threadStore, funName)
	if !p {
		panic("错误::::::表达式中的" + code + "函数调用失败,请检查函数是否存在返回值")
	}
	return variable1.Value
}
